// File main.cpp
//
// Purpose: The main function for the application
//
// Author : Bryson King (edited)
// Original Code Provided by: Mat Buckland 2002 (fup@ai-junkie.com)
// Date : 18 March 2013
// --------------------------------------------------------------
#define DEBUG_SECTION

#include <time.h>
#include <iostream>
#include <string>
#include "misc/ConsoleUtils.h"
#include <algorithm>
#include "MessageDispatcher.h"
#include "UserInterface.h"
#include "GameWorld.h"

int main()
{
	//create the game world
	CGameWorld* gameWorld = new CGameWorld();

	CUserInterface::StartUserInterface();

	try 
	{
		// Run the game world through update calls until the player quits or the game is over
		while (true)
		{
			// Call the Update function of the game world
			gameWorld->UpdateGameWorld();

			//dispatch any delayed messages
			Dispatch->DispatchDelayedMessages();

			// Check to see if the user wishes to quit the game or the game is over
			if (CUserInterface::UserRequestsQuitGame || CUserInterface::GameOver || CUserInterface::UserDied)
				break;
		}
	} catch (exception e)
	{
		//tidy up
		delete gameWorld;
	}

	//tidy up
	delete gameWorld;

	CUserInterface::EndUserInterface();

	return 0;
}